{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 72,
      "metadata": {
        "id": "nixnjmPWtdGq"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import seaborn as sns\n",
        "import joblib\n",
        "import sklearn\n",
        "from sklearn.preprocessing import LabelEncoder\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn.ensemble import RandomForestRegressor\n",
        "from sklearn.metrics import classification_report\n",
        "from sklearn.metrics import r2_score"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df=pd.read_csv(\"city_day.csv\",na_values=\"=\")"
      ],
      "metadata": {
        "id": "dB6kK_cr6uob"
      },
      "execution_count": 73,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 206
        },
        "id": "ji-Y4ezq7ACQ",
        "outputId": "ab9033d6-531a-4034-d543-e91a58da0035"
      },
      "execution_count": 74,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "        City        Date  PM2.5  PM10     NO    NO2    NOx  NH3     CO    SO2  \\\n",
              "0  Ahmedabad  2015-01-01    NaN   NaN   0.92  18.22  17.15  NaN   0.92  27.64   \n",
              "1  Ahmedabad  2015-01-02    NaN   NaN   0.97  15.69  16.46  NaN   0.97  24.55   \n",
              "2  Ahmedabad  2015-01-03    NaN   NaN  17.40  19.30  29.70  NaN  17.40  29.07   \n",
              "3  Ahmedabad  2015-01-04    NaN   NaN   1.70  18.48  17.97  NaN   1.70  18.59   \n",
              "4  Ahmedabad  2015-01-05    NaN   NaN  22.10  21.42  37.76  NaN  22.10  39.33   \n",
              "\n",
              "       O3  Benzene  Toluene  Xylene  AQI AQI_Bucket  \n",
              "0  133.36     0.00     0.02    0.00  NaN        NaN  \n",
              "1   34.06     3.68     5.50    3.77  NaN        NaN  \n",
              "2   30.70     6.80    16.40    2.25  NaN        NaN  \n",
              "3   36.08     4.43    10.14    1.00  NaN        NaN  \n",
              "4   39.31     7.01    18.89    2.78  NaN        NaN  "
            ],
            "text/html": [
              "\n",
              "\n",
              "  <div id=\"df-87601249-eb08-4677-8894-e7b0efd6ed4b\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>City</th>\n",
              "      <th>Date</th>\n",
              "      <th>PM2.5</th>\n",
              "      <th>PM10</th>\n",
              "      <th>NO</th>\n",
              "      <th>NO2</th>\n",
              "      <th>NOx</th>\n",
              "      <th>NH3</th>\n",
              "      <th>CO</th>\n",
              "      <th>SO2</th>\n",
              "      <th>O3</th>\n",
              "      <th>Benzene</th>\n",
              "      <th>Toluene</th>\n",
              "      <th>Xylene</th>\n",
              "      <th>AQI</th>\n",
              "      <th>AQI_Bucket</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Ahmedabad</td>\n",
              "      <td>2015-01-01</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>0.92</td>\n",
              "      <td>18.22</td>\n",
              "      <td>17.15</td>\n",
              "      <td>NaN</td>\n",
              "      <td>0.92</td>\n",
              "      <td>27.64</td>\n",
              "      <td>133.36</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.02</td>\n",
              "      <td>0.00</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Ahmedabad</td>\n",
              "      <td>2015-01-02</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>0.97</td>\n",
              "      <td>15.69</td>\n",
              "      <td>16.46</td>\n",
              "      <td>NaN</td>\n",
              "      <td>0.97</td>\n",
              "      <td>24.55</td>\n",
              "      <td>34.06</td>\n",
              "      <td>3.68</td>\n",
              "      <td>5.50</td>\n",
              "      <td>3.77</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Ahmedabad</td>\n",
              "      <td>2015-01-03</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>17.40</td>\n",
              "      <td>19.30</td>\n",
              "      <td>29.70</td>\n",
              "      <td>NaN</td>\n",
              "      <td>17.40</td>\n",
              "      <td>29.07</td>\n",
              "      <td>30.70</td>\n",
              "      <td>6.80</td>\n",
              "      <td>16.40</td>\n",
              "      <td>2.25</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Ahmedabad</td>\n",
              "      <td>2015-01-04</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>1.70</td>\n",
              "      <td>18.48</td>\n",
              "      <td>17.97</td>\n",
              "      <td>NaN</td>\n",
              "      <td>1.70</td>\n",
              "      <td>18.59</td>\n",
              "      <td>36.08</td>\n",
              "      <td>4.43</td>\n",
              "      <td>10.14</td>\n",
              "      <td>1.00</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Ahmedabad</td>\n",
              "      <td>2015-01-05</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>22.10</td>\n",
              "      <td>21.42</td>\n",
              "      <td>37.76</td>\n",
              "      <td>NaN</td>\n",
              "      <td>22.10</td>\n",
              "      <td>39.33</td>\n",
              "      <td>39.31</td>\n",
              "      <td>7.01</td>\n",
              "      <td>18.89</td>\n",
              "      <td>2.78</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-87601249-eb08-4677-8894-e7b0efd6ed4b')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "\n",
              "\n",
              "\n",
              "    <div id=\"df-20c8a309-8282-432c-b473-8607fe0c1e2c\">\n",
              "      <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-20c8a309-8282-432c-b473-8607fe0c1e2c')\"\n",
              "              title=\"Suggest charts.\"\n",
              "              style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "      </button>\n",
              "    </div>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "    background-color: #E8F0FE;\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: #1967D2;\n",
              "    height: 32px;\n",
              "    padding: 0 0 0 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: #E2EBFA;\n",
              "    box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: #174EA6;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "    background-color: #3B4455;\n",
              "    fill: #D2E3FC;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart:hover {\n",
              "    background-color: #434B5C;\n",
              "    box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "    filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "    fill: #FFFFFF;\n",
              "  }\n",
              "</style>\n",
              "\n",
              "    <script>\n",
              "      async function quickchart(key) {\n",
              "        const containerElement = document.querySelector('#' + key);\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      }\n",
              "    </script>\n",
              "\n",
              "      <script>\n",
              "\n",
              "function displayQuickchartButton(domScope) {\n",
              "  let quickchartButtonEl =\n",
              "    domScope.querySelector('#df-20c8a309-8282-432c-b473-8607fe0c1e2c button.colab-df-quickchart');\n",
              "  quickchartButtonEl.style.display =\n",
              "    google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "}\n",
              "\n",
              "        displayQuickchartButton(document);\n",
              "      </script>\n",
              "      <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-87601249-eb08-4677-8894-e7b0efd6ed4b button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-87601249-eb08-4677-8894-e7b0efd6ed4b');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 74
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.shape"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "WFssNDEg7CiL",
        "outputId": "0eef29d2-fc5b-4eed-e8b6-d42ddf51c508"
      },
      "execution_count": 75,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(29531, 16)"
            ]
          },
          "metadata": {},
          "execution_count": 75
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.dtypes"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "JjzmHwxl7E_I",
        "outputId": "cb293436-e5ad-4afe-c91f-2dc56ee11f25"
      },
      "execution_count": 76,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "City           object\n",
              "Date           object\n",
              "PM2.5         float64\n",
              "PM10          float64\n",
              "NO            float64\n",
              "NO2           float64\n",
              "NOx           float64\n",
              "NH3           float64\n",
              "CO            float64\n",
              "SO2           float64\n",
              "O3            float64\n",
              "Benzene       float64\n",
              "Toluene       float64\n",
              "Xylene        float64\n",
              "AQI           float64\n",
              "AQI_Bucket     object\n",
              "dtype: object"
            ]
          },
          "metadata": {},
          "execution_count": 76
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.isna().sum()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "D1T0vPjb7Wj_",
        "outputId": "6bac9045-73a9-4447-fa5d-2c69eed915ec"
      },
      "execution_count": 77,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "City              0\n",
              "Date              0\n",
              "PM2.5          4598\n",
              "PM10          11140\n",
              "NO             3582\n",
              "NO2            3585\n",
              "NOx            4185\n",
              "NH3           10328\n",
              "CO             2059\n",
              "SO2            3854\n",
              "O3             4022\n",
              "Benzene        5623\n",
              "Toluene        8041\n",
              "Xylene        18109\n",
              "AQI            4681\n",
              "AQI_Bucket     4681\n",
              "dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 77
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df=df.fillna(df.mean())"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "jm6WXMz-vBYb",
        "outputId": "a5ec0f84-e1ae-455f-c978-3db473fbeb56"
      },
      "execution_count": 78,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "<ipython-input-78-6f8c6f28e805>:1: FutureWarning: The default value of numeric_only in DataFrame.mean is deprecated. In a future version, it will default to False. In addition, specifying 'numeric_only=None' is deprecated. Select only valid columns or specify the value of numeric_only to silence this warning.\n",
            "  df=df.fillna(df.mean())\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "label_encoder = LabelEncoder()\n",
        "x=df[\"City\"]\n",
        "df[\"City\"] = label_encoder.fit_transform(df[\"City\"])\n",
        "\n",
        "df[\"AQI_Bucket\"] = label_encoder.fit_transform(df[\"AQI_Bucket\"])"
      ],
      "metadata": {
        "id": "tDaY288hwr0o"
      },
      "execution_count": 79,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print(\"Mapping of classes to labels:\")\n",
        "unique_labels = set()\n",
        "for city, label in zip(df[\"City\"], x):\n",
        "    y=f\"{city} -> {label}\"\n",
        "    unique_labels.add(y)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5JHM0eywIzAe",
        "outputId": "a273ceb8-e156-4f68-c71a-222d21e28826"
      },
      "execution_count": 80,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Mapping of classes to labels:\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(unique_labels)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "uo0VECA0LaC0",
        "outputId": "3d5c061b-3fe5-4e58-f114-95f56b4bbbd8"
      },
      "execution_count": 81,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'22 -> Shillong', '1 -> Aizawl', '21 -> Patna', '23 -> Talcher', '16 -> Jorapokhar', '15 -> Jaipur', '3 -> Amritsar', '8 -> Chennai', '19 -> Lucknow', '0 -> Ahmedabad', '11 -> Ernakulam', '7 -> Chandigarh', '5 -> Bhopal', '18 -> Kolkata', '6 -> Brajrajnagar', '13 -> Guwahati', '20 -> Mumbai', '25 -> Visakhapatnam', '10 -> Delhi', '17 -> Kochi', '12 -> Gurugram', '9 -> Coimbatore', '4 -> Bengaluru', '14 -> Hyderabad', '2 -> Amaravati', '24 -> Thiruvananthapuram'}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "ySj6v24BLXH6"
      },
      "execution_count": 81,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "df.head(10)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 363
        },
        "id": "Yh19nyaEw9Vy",
        "outputId": "d98034b9-2487-4328-92f6-95e72ef25ea9"
      },
      "execution_count": 82,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   City        Date      PM2.5        PM10         NO    NO2     NOx  \\\n",
              "0     0  2015-01-01  67.450578  118.127103    0.92000  18.22   17.15   \n",
              "1     0  2015-01-02  67.450578  118.127103    0.97000  15.69   16.46   \n",
              "2     0  2015-01-03  67.450578  118.127103   17.40000  19.30   29.70   \n",
              "3     0  2015-01-04  67.450578  118.127103    1.70000  18.48   17.97   \n",
              "4     0  2015-01-05  67.450578  118.127103   22.10000  21.42   37.76   \n",
              "5     0  2015-01-06  67.450578  118.127103   45.41000  38.48   81.50   \n",
              "6     0  2015-01-07  67.450578  118.127103  112.16000  40.62  130.77   \n",
              "7     0  2015-01-08  67.450578  118.127103   80.87000  36.74   96.75   \n",
              "8     0  2015-01-09  67.450578  118.127103   29.16000  31.00   48.00   \n",
              "9     0  2015-01-10  67.450578  118.127103   17.57473   7.04    0.00   \n",
              "\n",
              "         NH3          CO    SO2      O3  Benzene  Toluene  Xylene         AQI  \\\n",
              "0  23.483476    0.920000  27.64  133.36     0.00     0.02    0.00  166.463581   \n",
              "1  23.483476    0.970000  24.55   34.06     3.68     5.50    3.77  166.463581   \n",
              "2  23.483476   17.400000  29.07   30.70     6.80    16.40    2.25  166.463581   \n",
              "3  23.483476    1.700000  18.59   36.08     4.43    10.14    1.00  166.463581   \n",
              "4  23.483476   22.100000  39.33   39.31     7.01    18.89    2.78  166.463581   \n",
              "5  23.483476   45.410000  45.76   46.51     5.42    10.83    1.93  166.463581   \n",
              "6  23.483476  112.160000  32.28   33.47     0.00     0.00    0.00  166.463581   \n",
              "7  23.483476   80.870000  38.54   31.89     0.00     0.00    0.00  166.463581   \n",
              "8  23.483476   29.160000  58.68   25.75     0.00     0.00    0.00  166.463581   \n",
              "9  23.483476    2.248598   8.29    4.55     0.00     0.00    0.00  166.463581   \n",
              "\n",
              "   AQI_Bucket  \n",
              "0           6  \n",
              "1           6  \n",
              "2           6  \n",
              "3           6  \n",
              "4           6  \n",
              "5           6  \n",
              "6           6  \n",
              "7           6  \n",
              "8           6  \n",
              "9           6  "
            ],
            "text/html": [
              "\n",
              "\n",
              "  <div id=\"df-f69eb2f6-c42d-4614-8f33-27b152f97fbd\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>City</th>\n",
              "      <th>Date</th>\n",
              "      <th>PM2.5</th>\n",
              "      <th>PM10</th>\n",
              "      <th>NO</th>\n",
              "      <th>NO2</th>\n",
              "      <th>NOx</th>\n",
              "      <th>NH3</th>\n",
              "      <th>CO</th>\n",
              "      <th>SO2</th>\n",
              "      <th>O3</th>\n",
              "      <th>Benzene</th>\n",
              "      <th>Toluene</th>\n",
              "      <th>Xylene</th>\n",
              "      <th>AQI</th>\n",
              "      <th>AQI_Bucket</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-01</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>0.92000</td>\n",
              "      <td>18.22</td>\n",
              "      <td>17.15</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>0.920000</td>\n",
              "      <td>27.64</td>\n",
              "      <td>133.36</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.02</td>\n",
              "      <td>0.00</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-02</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>0.97000</td>\n",
              "      <td>15.69</td>\n",
              "      <td>16.46</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>0.970000</td>\n",
              "      <td>24.55</td>\n",
              "      <td>34.06</td>\n",
              "      <td>3.68</td>\n",
              "      <td>5.50</td>\n",
              "      <td>3.77</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-03</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>17.40000</td>\n",
              "      <td>19.30</td>\n",
              "      <td>29.70</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>17.400000</td>\n",
              "      <td>29.07</td>\n",
              "      <td>30.70</td>\n",
              "      <td>6.80</td>\n",
              "      <td>16.40</td>\n",
              "      <td>2.25</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-04</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>1.70000</td>\n",
              "      <td>18.48</td>\n",
              "      <td>17.97</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>1.700000</td>\n",
              "      <td>18.59</td>\n",
              "      <td>36.08</td>\n",
              "      <td>4.43</td>\n",
              "      <td>10.14</td>\n",
              "      <td>1.00</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-05</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>22.10000</td>\n",
              "      <td>21.42</td>\n",
              "      <td>37.76</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>22.100000</td>\n",
              "      <td>39.33</td>\n",
              "      <td>39.31</td>\n",
              "      <td>7.01</td>\n",
              "      <td>18.89</td>\n",
              "      <td>2.78</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-06</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>45.41000</td>\n",
              "      <td>38.48</td>\n",
              "      <td>81.50</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>45.410000</td>\n",
              "      <td>45.76</td>\n",
              "      <td>46.51</td>\n",
              "      <td>5.42</td>\n",
              "      <td>10.83</td>\n",
              "      <td>1.93</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-07</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>112.16000</td>\n",
              "      <td>40.62</td>\n",
              "      <td>130.77</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>112.160000</td>\n",
              "      <td>32.28</td>\n",
              "      <td>33.47</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-08</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>80.87000</td>\n",
              "      <td>36.74</td>\n",
              "      <td>96.75</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>80.870000</td>\n",
              "      <td>38.54</td>\n",
              "      <td>31.89</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-09</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>29.16000</td>\n",
              "      <td>31.00</td>\n",
              "      <td>48.00</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>29.160000</td>\n",
              "      <td>58.68</td>\n",
              "      <td>25.75</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>0</td>\n",
              "      <td>2015-01-10</td>\n",
              "      <td>67.450578</td>\n",
              "      <td>118.127103</td>\n",
              "      <td>17.57473</td>\n",
              "      <td>7.04</td>\n",
              "      <td>0.00</td>\n",
              "      <td>23.483476</td>\n",
              "      <td>2.248598</td>\n",
              "      <td>8.29</td>\n",
              "      <td>4.55</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>0.00</td>\n",
              "      <td>166.463581</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-f69eb2f6-c42d-4614-8f33-27b152f97fbd')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "\n",
              "\n",
              "\n",
              "    <div id=\"df-6a63497c-21e5-45e5-b233-b230cabd24e6\">\n",
              "      <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-6a63497c-21e5-45e5-b233-b230cabd24e6')\"\n",
              "              title=\"Suggest charts.\"\n",
              "              style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "      </button>\n",
              "    </div>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "    background-color: #E8F0FE;\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: #1967D2;\n",
              "    height: 32px;\n",
              "    padding: 0 0 0 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: #E2EBFA;\n",
              "    box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: #174EA6;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "    background-color: #3B4455;\n",
              "    fill: #D2E3FC;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart:hover {\n",
              "    background-color: #434B5C;\n",
              "    box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "    filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "    fill: #FFFFFF;\n",
              "  }\n",
              "</style>\n",
              "\n",
              "    <script>\n",
              "      async function quickchart(key) {\n",
              "        const containerElement = document.querySelector('#' + key);\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      }\n",
              "    </script>\n",
              "\n",
              "      <script>\n",
              "\n",
              "function displayQuickchartButton(domScope) {\n",
              "  let quickchartButtonEl =\n",
              "    domScope.querySelector('#df-6a63497c-21e5-45e5-b233-b230cabd24e6 button.colab-df-quickchart');\n",
              "  quickchartButtonEl.style.display =\n",
              "    google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "}\n",
              "\n",
              "        displayQuickchartButton(document);\n",
              "      </script>\n",
              "      <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-f69eb2f6-c42d-4614-8f33-27b152f97fbd button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-f69eb2f6-c42d-4614-8f33-27b152f97fbd');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 82
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df[\"AQI_Bucket\"]=df[\"AQI_Bucket\"].fillna(df[\"AQI_Bucket\"].mean())"
      ],
      "metadata": {
        "id": "gO5BGUmiwbQY"
      },
      "execution_count": 83,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "df[\"AQI_Bucket\"]"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "9PiYSlLYxGFi",
        "outputId": "e21af6d6-c7ff-49fb-c21b-6e9c84214b80"
      },
      "execution_count": 84,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0        6\n",
              "1        6\n",
              "2        6\n",
              "3        6\n",
              "4        6\n",
              "        ..\n",
              "29526    0\n",
              "29527    3\n",
              "29528    3\n",
              "29529    3\n",
              "29530    0\n",
              "Name: AQI_Bucket, Length: 29531, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 84
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df=df.drop(\"Date\",1)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "N9PEToioxj3s",
        "outputId": "24520e5d-f22b-4079-c403-a947749f7115"
      },
      "execution_count": 85,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "<ipython-input-85-7d3b58cc1798>:1: FutureWarning: In a future version of pandas all arguments of DataFrame.drop except for the argument 'labels' will be keyword-only.\n",
            "  df=df.drop(\"Date\",1)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "x = df.drop(\"AQI\", axis=1)\n",
        "y = df[\"AQI\"]"
      ],
      "metadata": {
        "id": "hvcIXxfPzGQ4"
      },
      "execution_count": 86,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)"
      ],
      "metadata": {
        "id": "sqq5nIAoznj5"
      },
      "execution_count": 87,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "model=RandomForestRegressor(max_depth=50,random_state=0)"
      ],
      "metadata": {
        "id": "CX2Hcsyx0bTH"
      },
      "execution_count": 88,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "model.fit(x_train,y_train)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 74
        },
        "id": "41yIBUer0r1K",
        "outputId": "ea6d8048-2d46-48a0-e206-ac8c3376d496"
      },
      "execution_count": 65,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "RandomForestRegressor(max_depth=50, random_state=0)"
            ],
            "text/html": [
              "<style>#sk-container-id-2 {color: black;background-color: white;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestRegressor(max_depth=50, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestRegressor</label><div class=\"sk-toggleable__content\"><pre>RandomForestRegressor(max_depth=50, random_state=0)</pre></div></div></div></div></div>"
            ]
          },
          "metadata": {},
          "execution_count": 65
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "y_pred=model.predict(x_test)"
      ],
      "metadata": {
        "id": "jIv--KzK0wSS"
      },
      "execution_count": 66,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "y_pred"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "J1gHAE1k09ox",
        "outputId": "8f4c17e8-4c4d-4be0-b00d-de08ff2ee11a"
      },
      "execution_count": 67,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([363.68      , 134.4025    , 157.81722334, ..., 333.8       ,\n",
              "        60.41      , 131.32      ])"
            ]
          },
          "metadata": {},
          "execution_count": 67
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "joblib.dump(model, 'randonforestregressormodel.pkl')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "xChw8K1E2f0u",
        "outputId": "1058236b-ffe9-4fcb-9b45-95b15ee9e600"
      },
      "execution_count": 69,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['randonforestregressormodel.pkl']"
            ]
          },
          "metadata": {},
          "execution_count": 69
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "r2_score(y_test,y_pred)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HhCQv02S1HS6",
        "outputId": "56070791-70e4-4135-833c-b9eb118b3507"
      },
      "execution_count": 68,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.9389440154254075"
            ]
          },
          "metadata": {},
          "execution_count": 68
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "feature_importances = model.feature_importances_\n",
        "print(\"Feature Importances:\")\n",
        "for feature, importance in zip(x_train.columns, feature_importances):\n",
        "    print(f\"{feature}: {importance:.4f}\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CVgBqiKAOSiP",
        "outputId": "ecd2c619-0d1d-49ad-e835-b181939e9887"
      },
      "execution_count": 71,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Feature Importances:\n",
            "City: 0.0055\n",
            "PM2.5: 0.4383\n",
            "PM10: 0.0221\n",
            "NO: 0.0214\n",
            "NO2: 0.0073\n",
            "NOx: 0.0074\n",
            "NH3: 0.0012\n",
            "CO: 0.3067\n",
            "SO2: 0.0059\n",
            "O3: 0.0057\n",
            "Benzene: 0.0029\n",
            "Toluene: 0.0040\n",
            "Xylene: 0.0035\n",
            "AQI_Bucket: 0.1682\n"
          ]
        }
      ]
    }
  ]
}